<strong></strong><template>
  <div class="shopList">
    <div id="imgbigbox" @click="hideBigImg()">
      <img
        id="imgTag"
        :src="thisimg"
        alt=""
        @load="loadImg()"
        @click.stop="stopPropagation()"
      />
    </div>
    <div class="shopList_bottom">
      <div class="new">
        <div class="shopList">
          <div class="new_goods_btn">
            <button @click="handerBanner">
              <i class="el-icon-trophy"></i>新增Banner类型
            </button>
            <!-- <div class="marketBox">
              <span>卖场：</span>
              <el-select
                v-model="marketId"
                clearable
                @change="selectMarket"
                filterable
                placeholder="请选择卖场"
              >
                <el-option
                  v-for="item in marketList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </div> -->
          </div>
          <div class="shopList_serch">
            <div class="shopList_serch_ipt">
              <el-select
                v-model="search.appType"
                placeholder="请选择banner类型"
                @change="handerSeach"
              >
                <el-option
                  v-for="item in appTypeList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <!--
							<el-input v-model="search.keyword" placeholder="请输入商品信息查询"></el-input>
							<button @click="handerSeach"><i class="el-icon-search"></i>搜索</button>
							-->
            </div>
          </div>
        </div>
      </div>

      <div class="shopList_table">
        <div class="shopList_bottom_table">
          <table>
            <tr>
              <th></th>
              <th>序号</th>
              <th>客户端类型</th>
              <th>banner类型</th>
              <th>备注</th>
              <th class="doShop">操作</th>
            </tr>
            <tr v-for="(v, i) in tableList" :key="i">
              <td>
                <font
                  class="checkbox"
                  :class="{ check_active: checkBoxAll.includes(i) }"
                  @click="handlerCheckbox(i)"
                  ><i class="el-icon-check"></i
                ></font>
              </td>
              <td>{{ v.id }}</td>
              <td>
                {{
                  v.apptype == 1
                    ? "用户小程序"
                    : v.apptype == 2
                    ? "合作方小程序"
                    : "其他"
                }}
              </td>
              <td>{{ v.name }}</td>
              <td>{{ v.desc }}</td>
              <!--
							<td>{{v.entry_status==1?'启用':'禁用'}}</td>
							-->
              <td class="doShop">
                <button class="editor" @click="toDetail(v.id)">详情</button>
                <!--
								<button class="shelves" :class="v.entry_status==0?'delete':''" @click="shelves(v.store_id,v.entry_status)">{{v.entry_status==1?'禁用':'启用'}}</button>
								-->
              </td>
            </tr>
            <tr v-if="tableList.length == 0">
              <td class="table_title" colspan="10">当前数据空空如也</td>
            </tr>
          </table>
        </div>

        <div class="shopList_bottom_page">
          <div class="shopList_bottom_page_left">
            <!--
						<div class="shopList_bottom_page_left_checkAll" @click="handerCheckAll">
							<font class="checkbox" :class="{'check_active' : checkAll}"><i class="el-icon-check"></i></font>
						</div>全选
						-->
            <!-- <button class="shopList_bottom_page_left_btn" @click="selectDel">删除</button> -->
          </div>
          <div class="shopList_bottom_page_right">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="page"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
              background
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user_id: null,
      checkAll: false,
      page: 1,
      pageSize: 10,
      total: 0,
      checkBoxAll: [], // 选中的数据
      shelvesAlls: [], //选中的数据
      tableList: [],
      search: {
        appType: "",
      },
      appTypeList: [
        { id: 0, name: "全部" },
        { id: 1, name: "用户小程序" },
        { id: 2, name: "合作方小程序" },
        /*
				{id:3,name:'合作方PC后台'},
				{id:4,name:'pc总后台'},
				*/
      ],
      thisimg: "",
      typeList: [],
      clientHeight: 0,
      marketId: "", //卖场id
      marketList: [],
    };
  },

  mounted() {
    let user_id = Number(localStorage.getItem("user_id"));
    this.user_id = user_id;
    this.getShopRoom();
    this.remoteMethod();
  },

  methods: {
    // 获取卖场列表
    remoteMethod() {
      this.$http.post("/api/root/Market/marketList").then((res) => {
        console.log(res, "卖场列表");
        if (res.code == 1) {
          this.marketList = res.data ? res.data : [];
        }
      });
    },
    // 选择卖场
    selectMarket() {
      this.page = 1
      this.pageSize =10
      this.getShopRoom();
    },
    // 获取商家列表
    getShopRoom(search = this.search) {
      this.$http
        .post("/api/root/Banner/typeList", {
          page: this.page,
          pagesize: this.pageSize,
          type: search.type,
          keyword: search.keyword,
          market_id:this.marketId
        })
        .then((res) => {
          console.log(res);
          if (res.code == 1) {
            this.tableList = res.data.list ? res.data.list : [];
            this.total = res.data.total;
          }
        })
        .catch((err) => {
          this.$message({
            type: "error",
            message: err,
          });
        });
    },

    //新增banner按钮
    handerBanner() {
      this.$router.push({ path: "/bannerTypeDetail" });
    },

    // 搜索
    handerSeach() {
      this.getShopRoom(this.search);
    },

    // 详情
    toDetail(id) {
      this.$router.push({ path: "/bannerTypeDetail", query: { id } });
    },

    /*
        // 禁用和启用按钮
        shelves(id,entry_status){
			let is_reco=entry_status==1?0:1;
			this.$http.post('/api/root/StoreShop/enable',{store_id_lst:id,entry_status:is_reco}).then(res=>{
				console.log(res);
				if(res.code==1){
					this.getShopRoom()
					this.$message({
						type:'success',
						message:'操作成功'
					})
				}else{
					this.$message({
						type:'warning',
						message:res.msg
					})
				}
			})
		},
		*/

    /*
          // 多选
			handlerCheckbox(i){
                console.log(i);
				let arr = this.checkBoxAll;
				if(arr.includes(i)){
					let index = arr.indexOf(i);
					if(index != -1){
						arr.splice(index,1);
						this.shelvesAlls.splice(index,1);
						if(this.checkBoxAll.length !== this.tableList.length) {
							this.checkAll = false;
						}
					}
				}else {
					this.checkBoxAll.push(i);
					this.shelvesAlls.push(this.tableList[i].store_id);
					if(this.checkBoxAll.length == this.tableList.length) {
						this.checkAll = true;
					}
				};
				console.log(this.shelvesAlls);
			},
            // 全选与全不选
			handerCheckAll(){
				this.checkAll = !this.checkAll;
				let arr = this.tableList.length;
				this.checkBoxAll = [];
				this.shelvesAlls = [];
				if(this.checkAll){
					for(let i=0;i<arr;i++){
						this.checkBoxAll.push(i);
					}
					this.checkBoxAll.map(v => {
					this.shelvesAlls.push(this.tableList[v].store_id.toString());;
				})
				}else {
					this.checkBoxAll = [];
					this.shelvesAlls = []
				}
				console.log(this.shelvesAlls);
			},

           */

    handleSizeChange(val) {
      this.pageSize = val;
      console.log(val);
      this.getShopRoom();
    },
    handleCurrentChange(val) {
      this.page = val;
      console.log(val);
      this.getShopRoom();
    },
  },
};
</script>
<style lang="less" scoped>
@import "bannerTypeList.less";
</style>
<style>
#imgbigbox {
  width: 100%;
  height: 100%;
  position: fixed;
  z-index: 999;
  display: none;
  background-color: rgba(0, 0, 0, 0.6);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
#imgbigbox img {
  max-width: 70%;
  max-height: 80%;
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>

